
package com.hzt.business.controller;

import com.hzt.business.domain.Sales;
import com.hzt.business.service.SalesService;
import com.hzt.business.vo.SalesVo;
import com.hzt.system.common.ActiveUser;
import com.hzt.system.common.ResultObj;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;


/**
 *
 *
 * @Author:hzt
 * @Date:6:52 下午 2020/7/25
 */
@RequestMapping("api/sales")
@RestController
public class SalesController {

    @Autowired
    private SalesService salesService;

    @RequestMapping("loadAllSales")
    public Object loadAllSales(SalesVo salesVo){
        return this.salesService.queryAllSales(salesVo);
    }


    @RequestMapping("addSales")
    public ResultObj addSales(Sales sales){

        try {
            ActiveUser activeUser = (ActiveUser) SecurityUtils.getSubject().getPrincipal();
            String name = activeUser.getUser().getName();
            sales.setOperateperson(name);
            sales.setSalestime(new Date());
            salesService.saveSales(sales);
            return  ResultObj.ADD_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return  ResultObj.ADD_SUCCESS;
        }
    }


    @RequestMapping("updateSales")
    public ResultObj updateSales(Sales sales){
        try {
            salesService.updateSales(sales);
            return ResultObj.UPDATE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.UPDATE_ERROR;
        }
    }


    @RequestMapping("deleteSales")
    public ResultObj deleteSales(Sales sales){
        try {
            salesService.removeById(sales.getId());
            return ResultObj.DELETE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.DELETE_ERROR;
        }
    }




}
